package cn.iocoder.yudao.module.biz.controller.admin.htPlanDetailExe;

import cn.iocoder.yudao.module.infra.dal.dataobject.oss.OssDO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.text.ParseException;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.biz.controller.admin.htPlanDetailExe.vo.*;
import cn.iocoder.yudao.module.biz.dal.dataobject.htPlanDetailExe.HtPlanDetailExeDO;
import cn.iocoder.yudao.module.biz.convert.htPlanDetailExe.HtPlanDetailExeConvert;
import cn.iocoder.yudao.module.biz.service.htPlanDetailExe.HtPlanDetailExeService;

@Api(tags = "管理后台 - 排查项目计划执行结果")
@RestController
@RequestMapping("/biz/ht-plan-detail-exe")
@Validated
public class HtPlanDetailExeController {

    @Resource
    private HtPlanDetailExeService htPlanDetailExeService;

    @PostMapping("/create")
    @ApiOperation("创建排查项目计划执行结果")
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail-exe:create')")
    public CommonResult<String> createHtPlanDetailExe(@Valid @RequestBody HtPlanDetailExeCreateReqVO createReqVO) throws ParseException {
        return success(htPlanDetailExeService.createHtPlanDetailExe(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新排查项目计划执行结果")
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail-exe:update')")
    public CommonResult<Boolean> updateHtPlanDetailExe(@Valid @RequestBody HtPlanDetailExeUpdateReqVO updateReqVO) {
        htPlanDetailExeService.updateHtPlanDetailExe(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除排查项目计划执行结果")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail-exe:delete')")
    public CommonResult<Boolean> deleteHtPlanDetailExe(@RequestParam("id") String id) {
        htPlanDetailExeService.deleteHtPlanDetailExe(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得排查项目计划执行结果")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail-exe:query')")
    public CommonResult<HtPlanDetailExeRespVO> getHtPlanDetailExe(@RequestParam("id") String id) {
        HtPlanDetailExeDO htPlanDetailExe = htPlanDetailExeService.getHtPlanDetailExe(id);
        //根据ID查询图片列表
        List<OssDO> ossImg=htPlanDetailExeService.getImgList(id);
        HtPlanDetailExeRespVO respVO=HtPlanDetailExeConvert.INSTANCE.convert(htPlanDetailExe);
        respVO.setOssImg(ossImg);
        return success(respVO);
    }

    @GetMapping("/list")
    @ApiOperation("获得排查项目计划执行结果列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail-exe:query')")
    public CommonResult<List<HtPlanDetailExeRespVO>> getHtPlanDetailExeList(@RequestParam("ids") Collection<String> ids) {
        List<HtPlanDetailExeDO> list = htPlanDetailExeService.getHtPlanDetailExeList(ids);
        return success(HtPlanDetailExeConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得排查项目计划执行结果分页")
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail-exe:query')")
    public CommonResult<PageResult<HtPlanDetailExeRespVO>> getHtPlanDetailExePage(@Valid HtPlanDetailExePageReqVO pageVO) {
        PageResult<HtPlanDetailExeDO> pageResult = htPlanDetailExeService.getHtPlanDetailExePage(pageVO);
        return success(HtPlanDetailExeConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出排查项目计划执行结果 Excel")
//    @PreAuthorize("@ss.hasPermission('biz:ht-plan-detail-exe:export')")
    @OperateLog(type = EXPORT)
    public void exportHtPlanDetailExeExcel(@Valid HtPlanDetailExeExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<HtPlanDetailExeDO> list = htPlanDetailExeService.getHtPlanDetailExeList(exportReqVO);
        // 导出 Excel
        List<HtPlanDetailExeExcelVO> datas = HtPlanDetailExeConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "排查项目计划执行结果.xls", "数据", HtPlanDetailExeExcelVO.class, datas);
    }

}
